//定义测试项目详细信息表单的基类
Ext.define('testProjectFormBase', {
    extend: 'Ext.form.Panel',
    title: '测试项目详情',
    bodyPadding: 10,
    border: false,
    defaults: {
        anchor: '100%',
        layout: 'column', // 默认定义组件内部元素为布局为列布局方式
        border: false
    },
    items: [{
        defaults: {
            border: false,
            layout: 'form',
        },
        items: [{
            columnWidth: .5, // 该列占用的宽度，标识为50％
            items: [{
                xtype: 'textfield',
                labelWidth: 50,
                allowBlank: false,
                fieldLabel: '项目名称',
                name: 'name',
                emptyText: '限制字数',
                itemId: 'name'
            }]
        }, {
            columnWidth: .5, //该列占用的宽度，标识为50％
            items: [{
                xtype: 'button',
                text: '结算成绩',
                itemId: 'settleGradeButton',
                listeners: [{
                    click: function () {
                        var selectArray = classesLeftTreePanel.getSelectionModel().getSelected();// 得到被选择的行的数组.
                        var projectId = selectArray.items[0].data.id;
                        Ext.Ajax.request({
                            url: zuulUrl + '/' + testServiceName + '/testProject/testProcess/isOver/' + projectId,
                            async: true, // ASYNC 是否异步( TRUE 异步 , FALSE 同步)
                            success: function (response, opts) {
                                if (response.responseText != 1) {
                                    Ext.MessageBox.confirm('结算', '该项目还未结束,你确定要结算该项目吗?', function (btn) {
                                        if (btn === 'yes')
                                            settleGradeForProject(projectId);
                                    });
                                } else
                                    settleGradeForProject(projectId);
                            },
                            failure: function (response, opts) {
                                var obj = Ext.decode(response.responseText);
                                if (obj.code == 401 || obj.code == 402 || obj.code == 403 || obj.code == 406 || obj.code == 407)
                                    Ext.Msg.alert("错误", obj.message);
                                else
                                    Ext.Msg.alert("错误", "该功能暂时不可用！");
                            }
                        });
                    }
                }]
            }, {
                xtype: 'button',
                margin: '0 0 0 5',
                text: '通知成绩已公布',
                itemId: 'noticeGradePublicButton',
                listeners: [{
                    click: function () {
                        var selectArray = classesLeftTreePanel.getSelectionModel().getSelected();// 得到被选择的行的数组.
                        var projectId = selectArray.items[0].data.id;
                        Ext.Ajax.request({
                            url: zuulUrl + '/' + testServiceName + '/testProject/testProcess/isOver/' + projectId,
                            async: true, // ASYNC 是否异步( TRUE 异步 , FALSE 同步)
                            success: function (response, opts) {
                                if (response.responseText != 1) {
                                    Ext.MessageBox.confirm('通知', '该项目还未结束,你确定公布该项目成绩吗?', function (btn) {
                                        if (btn === 'yes')
                                            noticeGradeIsPublic(projectId);
                                    });
                                } else
                                    noticeGradeIsPublic(projectId);
                            },
                            failure: function (response, opts) {
                                var obj = Ext.decode(response.responseText);
                                if (obj.code == 401 || obj.code == 402 || obj.code == 403 || obj.code == 406 || obj.code == 407)
                                    Ext.Msg.alert("错误", obj.message);
                                else
                                    Ext.Msg.alert("错误", "该功能暂时不可用！");
                            }
                        });
                    }
                }]
            }]
        }]
    }, {
        defaults: {
            border: false,
            layout: 'form',
            margin: '20 0 0 0'
        },
        items: [{
            columnWidth: .5, //该列占用的宽度，标识为50％
            items: [{
                xtype: 'displayfield',
                fieldLabel: '测试系统:',
                margin: '20 0 0 5',
                labelWidth: 70,
                itemId: 'system',
                renderer: function (value) {
                    return value == "" || null ? '不详' : value;
                }
            }]
        }, {
            columnWidth: .3,
            items: [{
                xtype: 'button',
                text: '选择',
                itemId: 'systemButton',
                listeners: [{
                    click: function () {
                        testSystemGridStore.reload();
                        testProjectChooseSystemWin.show();
                    }
                }]
            }]
        }]
    }, {
        defaults: {
            border: false,
            layout: 'form',
            margin: '20 0 0 0'
        },
        items: [{
            columnWidth: .5, //该列占用的宽度，标识为50％
            items: [{
                xtype: 'displayfield',
                fieldLabel: '所属组:',
                margin: '20 0 0 5',
                labelWidth: 70,
                itemId: 'group',
                renderer: function (value) {
                    return value == "" || null ? '不详' : value;
                }
            }]
        }, {
            columnWidth: .3,
            items: [{
                xtype: 'button',
                text: '选择',
                itemId: 'groupButton',
                listeners: [{
                    click: function () {
                        testProjectChooseGroupStore.reload();
                        testProjectChooseGroupWin.show();
                    }
                }]
            }]
        }]
    }, {
        defaults: {
            border: false,
            layout: 'form',
            margin: '20 0 0 0'
        },
        items: [{
            columnWidth: .5, // 该列占用的宽度，标识为50％
            items: [{
                xtype: 'displayfield',
                fieldLabel: '创建时间:',
                labelWidth: 70,
                itemId: 'createDate',
                renderer: function (v, record) {
                    return v.replace('T', ' ');
                }
            }]
        }, {
            columnWidth: .5,
            items: [{
                xtype: 'displayfield',
                fieldLabel: '负责人:',
                labelWidth: 70,
                itemId: 'leadingCadre'
            }]
        }]
    }, {
        fieldLabel: '描述信息',
        margin: '20 0 0 5',
        allowBlank: false,
        labelWidth: 70,
        xtype: 'textareafield',
        height: '55%',
        itemId: 'describe',
        cls: 'x-form-valid',
        emptyText: '填写描述信息'
    }],
    buttons: [{
        text: '返回',
        itemId: 'backButton',
        listeners: [{
            click: function () {
                testProjectBackClick(this.up('form').pattern);
            }
        }]
    }, {
        text: '保存',
        itemId: 'saveButton',
        listeners: [{
            click: function () {
                testProjectSaveDetail();
            }
        }]
    }],
    constructor: function () {
        this.callParent(arguments); // 调用父类的构造函数,不然会报错
        this.pattern = arguments[0];// 判断这个是哪一个模式，0是给老师的项目管理界面用,1是给班级管理的项目节点详情使用，2是给主任的项目管理界面使用
        this.down('#name').setReadOnly(this.pattern == 0 || this.pattern == 2);
        this.down('#systemButton').setHidden(this.pattern == 0 || this.pattern == 2);
        this.down('#groupButton').setHidden(this.pattern == 0 || this.pattern == 2);
        this.down('#backButton').setHidden(this.pattern == 0);
        this.down('#saveButton').setHidden(this.pattern == 0 || this.pattern == 2);
        this.down('#describe').setReadOnly(this.pattern == 0 || this.pattern == 2);
        this.down('#settleGradeButton').setHidden(!this.pattern == 0 || this.pattern == 2);
        this.down('#noticeGradePublicButton').setHidden(!this.pattern == 0 || this.pattern == 2);
    }
});

//定义测试流程有checkBox的fieldSet的基类
Ext.define('processFieldset', {
    extend: 'Ext.form.FieldSet',
    collapsed: true,//设定展开状态初始为不展开
    checkboxToggle: true,
    padding: 20,
    defaults: {
        anchor: '100%',
        layout: 'column', //默认定义组件内部元素为布局为列布局方式
        border: false,
    },
    items: [{
        defaults: {
            border: false,
            layout: 'form',
            margin: '20 0 0 0',
        },
        items: [{
            columnWidth: .5, //该列占用的宽度，标识为50％
            items: [{
                xtype: 'datefield',
                width: 150,
                fieldLabel: '开始日期',
                allowBlank: false,
                format: 'Y-m-d',
                itemId: 'beginDate'
            }]
        }, {
            columnWidth: .5,
            items: [{
                xtype: 'timefield',
                width: 150,
                itemId: 'beginTime',
                fieldLabel: '开始时间',
                allowBlank: false,
                minValue: '06:00',
                maxValue: '24:00',
                increment: 1,
                anchor: '100%',
                format: 'H:i'
            }]
        }]
    }, {
        defaults: {
            border: false,
            layout: 'form',
            margin: '20 0 0 0'
        },
        items: [{
            columnWidth: .5, //该列占用的宽度，标识为50％
            items: [{
                xtype: 'datefield',
                width: 150,
                fieldLabel: '结束日期',
                format: 'Y-m-d',
                allowBlank: false,
                itemId: 'endDate'
            }]
        }, {
            columnWidth: .5,
            items: [{
                xtype: 'timefield',
                itemId: 'endTime',
                width: 150,
                allowBlank: false,
                fieldLabel: '结束时间',
                minValue: '06:00',
                maxValue: '24:00',
                increment: 1,
                anchor: '100%',
                format: 'H:i'
            }]
        }]
    }, {
        fieldLabel: '阶段结束时通知你去评分',
        itemId: 'isNotice',
        margin: '20 0 0 0',
        labelWidth: 200,
        xtype: 'checkboxfield',
        boxLabel: '是'
    }]
});

//定义测试流程没有有checkBox的fieldSet的基类
Ext.define('processNoCheckBoxFieldset', {
    extend: 'Ext.form.FieldSet',
    checkboxToggle: false,
    padding: 20,
    defaults: {
        anchor: '100%',
        layout: 'column', //默认定义组件内部元素为布局为列布局方式
        border: false,
    },
    items: [{
        defaults: {
            border: false,
            layout: 'form',
            margin: '20 0 0 0',
        },
        items: [{
            columnWidth: .5, //该列占用的宽度，标识为50％
            items: [{
                xtype: 'datefield',
                width: 150,
                fieldLabel: '开始日期',
                allowBlank: false,
                format: 'Y-m-d',
                itemId: 'beginDate'
            }]
        }, {
            columnWidth: .5,
            items: [{
                xtype: 'timefield',
                width: 150,
                itemId: 'beginTime',
                fieldLabel: '开始时间',
                allowBlank: false,
                minValue: '06:00',
                maxValue: '24:00',
                increment: 1,
                anchor: '100%',
                format: 'H:i'
            }]
        }]
    }, {
        defaults: {
            border: false,
            layout: 'form',
            margin: '20 0 0 0'
        },
        items: [{
            columnWidth: .5, //该列占用的宽度，标识为50％
            items: [{
                xtype: 'datefield',
                width: 150,
                fieldLabel: '结束日期',
                format: 'Y-m-d',
                allowBlank: false,
                itemId: 'endDate'
            }]
        }, {
            columnWidth: .5,
            items: [{
                xtype: 'timefield',
                itemId: 'endTime',
                width: 150,
                allowBlank: false,
                fieldLabel: '结束时间',
                minValue: '06:00',
                maxValue: '24:00',
                increment: 1,
                anchor: '100%',
                format: 'H:i'
            }]
        }]
    }, {
        fieldLabel: '将此测试流程通知项目所属组员',
        itemId: 'isNoticeGroupMember',
        margin: '20 0 0 0',
        labelWidth: 200,
        xtype: 'checkboxfield',
        boxLabel: '是'
    }]
});

//定义测试评分标准的fieldSet的基类
Ext.define('gradeRuleFieldset', {
    extend: 'Ext.form.FieldSet',
    collapsed: true,//设定展开状态初始为不展开
    checkboxToggle: true,
    padding: 20,
    defaults: {
        anchor: '100%',
        layout: 'column', //默认定义组件内部元素为布局为列布局方式
        border: false,
    },
    items: [{
        defaults: {
            border: false,
            layout: 'form',
            margin: '20 0 0 0',
        },
        items: [{
            columnWidth: .5, //该列占用的宽度，标识为50％
            items: [{
                xtype: 'numberfield',
                anchor: '100%',
                fieldLabel: '评分占比',
                allowBlank: false,
                itemId: 'percent',
                value: 0,
                maxValue: 100,
                minValue: 0
            }]
        }, {
            columnWidth: .5,
            items: [{
                xtype: 'numberfield',
                anchor: '100%',
                fieldLabel: '保底分数',
                allowBlank: false,
                value: 0,
                itemId: 'floors',
                maxValue: 100,
                minValue: 0
            }]
        }]
    }]
});

//定义测试评分标准的考勤的fieldSet的基类
Ext.define('gradeRuleCheckOnWorkFieldset', {
    extend: 'Ext.form.FieldSet',
    collapsed: true,//设定展开状态初始为不展开
    checkboxToggle: true,
    padding: 20,
    defaults: {
        anchor: '100%',
        layout: 'column', //默认定义组件内部元素为布局为列布局方式
        border: false,
    },
    items: [{
        defaults: {
            border: false,
            layout: 'form',
            margin: '20 0 0 0',
        },
        items: [{
            columnWidth: .5, //该列占用的宽度，标识为50％
            items: [{
                xtype: 'datefield',
                width: 150,
                fieldLabel: '开始日期',
                allowBlank: false,
                format: 'Y-m-d',
                itemId: 'beginDate'
            }]
        }, {
            columnWidth: .5,
            items: [{
                xtype: 'datefield',
                width: 150,
                fieldLabel: '结束日期',
                format: 'Y-m-d',
                allowBlank: false,
                itemId: 'endDate'
            }]
        }]
    }, {
        defaults: {
            border: false,
            layout: 'form',
            margin: '20 0 0 0'
        },
        items: [{
            columnWidth: .5, //该列占用的宽度，标识为50％
            items: [{
                xtype: 'timefield',
                width: 150,
                itemId: 'beginTime',
                fieldLabel: '开始时间',
                allowBlank: false,
                minValue: '06:00',
                maxValue: '24:00',
                increment: 5,
                anchor: '100%',
                format: 'H:i'
            }]
        }, {
            columnWidth: .5,
            items: [{
                xtype: 'timefield',
                itemId: 'endTime',
                width: 150,
                allowBlank: false,
                fieldLabel: '结束时间',
                minValue: '06:00',
                maxValue: '24:00',
                increment: 5,
                anchor: '100%',
                format: 'H:i'
            }]
        }]
    }, {
        defaults: {
            border: false,
            layout: 'form',
            margin: '20 0 0 0'
        },
        items: [{
            columnWidth: .5, //该列占用的宽度，标识为50％
            items: [{
                xtype: 'numberfield',
                anchor: '100%',
                itemId: 'missOneDeduct',
                fieldLabel: '缺一次考勤扣多少分',
                allowBlank: false,
                value: 0,
                maxValue: 100,
                minValue: 0
            }]
        }, {
            columnWidth: .5,
            items: [{
                xtype: 'numberfield',
                anchor: '100%',
                itemId: 'missDeadTime',
                fieldLabel: '考勤缺多少次丧失总成绩',
                allowBlank: false,
                value: 1,
                maxValue: 100,
                minValue: 1
            }]
        }]
    }, {
        xtype: 'numberfield',
        anchor: '100%',
        labelWidth: 60,
        fieldLabel: '评分占比',
        allowBlank: false,
        itemId: 'percent',
        value: 0,
        maxValue: 100,
        minValue: 0
    }]
});

//定义测试评分标准的自定义评分标准的fieldSet的基类
Ext.define('gradeRuleOtherFieldset', {
    extend: 'Ext.form.FieldSet',
    collapsed: true,//设定展开状态初始为不展开
    checkboxToggle: true,
    padding: 20,
    defaults: {
        anchor: '100%',
        layout: 'column', //默认定义组件内部元素为布局为列布局方式
        border: false,
    },
    items: [{
        defaults: {
            border: false,
            layout: 'form',
            margin: '20 0 0 0',
        },
        items: [{
            columnWidth: .5, //该列占用的宽度，标识为50％
            items: [{
                xtype: 'textfield',
                anchor: '100%',
                fieldLabel: '标准名称',
                allowBlank: false,
                itemId: 'name'
            }]
        }, {
            columnWidth: .5,
            items: [{
                xtype: 'numberfield',
                anchor: '100%',
                fieldLabel: '评分占比',
                allowBlank: false,
                value: 0,
                itemId: 'percent',
                maxValue: 100,
                minValue: 0
            }]
        }]
    }]
});

//定义测试评分标准的团队评分标准的fieldSet的基类
Ext.define('gradeRuleTeamFieldset', {
    extend: 'Ext.form.FieldSet',
    collapsed: true,//设定展开状态初始为不展开
    checkboxToggle: true,
    padding: 20,
    items: [{
        xtype: 'numberfield',
        anchor: '100%',
        fieldLabel: '平均分占比',
        allowBlank: false,
        value: 0,
        itemId: 'averagePercent',
        maxValue: 100,
        minValue: 0
    }, {
        xtype: 'numberfield',
        anchor: '100%',
        fieldLabel: '需求覆盖率占比',
        allowBlank: false,
        value: 0,
        itemId: 'trqCoverPercent',
        maxValue: 100,
        minValue: 0
    }]
});

//定义测试评分标准的团队评分占个人总评分的fieldSet的基类
Ext.define('gradeRuleTeamGradeInPersonGradeFieldset', {
    extend: 'Ext.form.FieldSet',
    collapsed: true,//设定展开状态初始为不展开
    checkboxToggle: true,
    padding: 20,
    items: [{
        xtype: 'numberfield',
        anchor: '100%',
        fieldLabel: '评分占比',
        allowBlank: false,
        value: 0,
        itemId: 'percent',
        maxValue: 100,
        minValue: 0
    }]
});